package me.keiwu.user.controller;

import me.keiwu.pub.data.Response;
import me.keiwu.pub.util.ContextUtil;
import me.keiwu.user.service.ItemService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by kei on 25/11/2017.
 */
@RestController
@RequestMapping("/item")
public class ItemController {

    private Logger logger = LoggerFactory.getLogger(ItemController.class);

    @Autowired
    private ItemService itemService;

    // 头像
    @ResponseBody
    @RequestMapping("/list")
    public Response listItem(HttpServletRequest request,
                             @RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size) {
        Long userId = ContextUtil.getLoginUserId(request);
        return Response.ok(itemService.getShelveItems(userId, page, size));
    }

    @ResponseBody
    @RequestMapping("/exchange")
    public Response exchangeItem(HttpServletRequest request, Integer itemId) {
        Long userId = ContextUtil.getLoginUserId(request);
        return itemService.exchangeItem(userId, itemId);
    }


    @ResponseBody
    @RequestMapping("/avatar/select")
    public Response selectAvatar(HttpServletRequest request, Integer singleId) {
        Long userId = ContextUtil.getLoginUserId(request);
        return itemService.setCombAvatar(userId, singleId);
    }

}
